package com.redshark.wmm.MeasurementProcessing;


public class BatteryProcessor {
	private final static int MAX_BATTERY = 9;
	private final static int BATTERY_THRESHOLD = 6;
	
	public static int checkBattery(int[] data) {
		double value = MeasurementProcessor.AD_CONSTANT * data[0] * 3;
		value = ((value - BATTERY_THRESHOLD)/(MAX_BATTERY-BATTERY_THRESHOLD))*100;
		
		return round(value);

	}
	private static int round(double d){
	    double dAbs = Math.abs(d);
	    int i = (int) dAbs;
	    double result = dAbs - (double) i;
	    if(result<0.5){
	        return d<0 ? -i : i;            
	    }else{
	        return d<0 ? -(i+1) : i+1;          
	    }
	}
}
